<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>求数组里有多少 true</title>
</head>

<body>
  <script>
    let nums = [true, 2, 3, true, true, 8, 9, true];

    let res = nums.filter((num) => {
      return num === true;
    });

    console.log(res);

  </script>
</body>

</html>